package com.paradogs.generator.misc;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: yumi
 * @date: 2023/12/5  21:51
 * @Description: TODO
 */
@Slf4j
@Getter
public class ExcelDataGeneratorListener extends AnalysisEventListener<LinkedHashMap<Integer, String>> {

    private List<LinkedHashMap<Integer, String>> data = new ArrayList<>();


    /**
     * Excel 获取到每一条数据都会执行一次
     * @param bean
     * @param analysisContext
     */
    @Override
    public void invoke(LinkedHashMap<Integer, String> bean, AnalysisContext analysisContext) {
        data.add(bean);
        log.info("add：[{}]", bean);
    }

    /**
     * 获取所有数据后执行
     * @param analysisContext
     */
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
//        log.info("表格读取完成");
    }


    /**
     * 读取表头信息
     * @param headMap
     * @param context
     */
    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
//       log.info("表头信息：[{}]", headMap);
    }


    @Override
    public void onException(Exception exception, AnalysisContext context) throws Exception {
        log.error("表格读取发生异常：[{}]", exception.getMessage());
    }

}
